// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

#define int long long

int t, n, p;
const int N = 2e5+50;

int pre[N];

int cnt[N];
char s[N];
int len[N];

int bin(int a, int b, int p) {
    int res = 1;
    for (a%=p; b; b>>=1, a=a*a%p)
        if (b & 1)
            res = res * a % p;
    return res;
}

int check() {
    int ans = 0;
    for (int i=1; i<=n; ++i)
        for (int j=i; j<=n; ++j) {
            int res = 0;
            for (int k=i; k<=j; ++k)
                res = (res * 10 + s[k] - '0') % p;
            // dbg(i, j, res);
            ans += res == 0;
        }
    return ans;
}

signed main() {
    // code

    scanf("%lld%lld%s", &n, &p, s+1);

    if (p == 2 || p == 5) {
        LL ans = 0;
        for (int i=1; i<=n; ++i) {
            if ((s[i] - '0') % p == 0)
                ans += i;
        }
        cout << ans << endl;
        return 0;
    }
    // pre[0] = 1;
    for (int i=1; i<=n; ++i)
        pre[i] = (pre[i-1] * 10 + s[i] - '0') % p;
    int inv10 = bin(10, p-2, p);
    // dbg(inv10);

    len[0] = 1;
    for (int i=1; i<=n; ++i)
        len[i] = len[i-1] * inv10 % p;
    for (int i=1; i<=n; ++i) {
        ++cnt[pre[i] * len[i] % p];
        // dbg(i, pre[i]);
    }


    LL ans = cnt[0];
    // dbg(ans);
    --cnt[pre[1] * len[1] % p];
    for (int i=2; i<=n; ++i) {
        ans += cnt[pre[i-1] * len[i-1] % p];
        --cnt[pre[i] * len[i] % p];
    }
    cout << ans << endl;
    // cout << check() << endl;
    // dbg(check());
    return 0;
}
